package gac.helloworld;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;

public class AlarmNotificationActivity extends Activity {
	String finalDest="";
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Intent i = getIntent();
		if(i!=null){
			Bundle b = i.getExtras();
			if(b!=null){
				finalDest = b.getString(AlarmDbAdapter.KEY_DESTINATION);
			}
		}
		AlertDialog dialog=new AlertDialog.Builder(AlarmNotificationActivity.this).create();
		dialog.setTitle("It's Time to Leave!");
		dialog.setButton("Start Nav",
				new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int whichButton)
			{
				Log.w("", finalDest);
				Intent i = new Intent(Intent.ACTION_VIEW, 
						Uri.parse("google.navigation:q="+finalDest)); //must change to actual destination
				startActivity(i); 
			}
		});
		dialog.setButton2("Dismiss",
				new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int whichButton)
			{
				finish();
				stopService(new Intent(AlarmNotificationActivity.this, LocateService.class));
			}
		});
		dialog.setButton3("Snooze",
				new DialogInterface.OnClickListener()
		{
			public void onClick(DialogInterface dialog, int whichButton)
			{
				/*Timer timer = new Timer();
				timer.schedule(new TimerTask(){
					public void run() {
						Log.v("x", "need new notification");

						Intent i = new Intent(getApplicationContext(), AlarmNotificationActivity.class);
		        		startActivity(i);
					}},5000); //change time interval to 5 minutes*/
				/*String ns = Context.NOTIFICATION_SERVICE;
				NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
				int icon = R.drawable.icon;
				CharSequence tickerText = "It's time to leave!";
				long when = System.currentTimeMillis();

				Notification notification = new Notification(icon, tickerText, when);
				notification.defaults |= Notification.DEFAULT_SOUND;
				Context context = getApplicationContext();
				CharSequence contentTitle = "It's time to leave!";
				CharSequence contentText = "";
				Intent i = new Intent(getApplicationContext(), AlarmNotificationActivity.class);
				PendingIntent contentIntent = PendingIntent.getActivity(alarmActivity, 0, i, 0);

				notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
				mNotificationManager.notify(1, notification);*/
			}
		});

		dialog.show();
		setContentView(R.layout.main);
	}
}
